package com.klz.consumer.service;

import com.klz.consumer.rpc.HelloClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by kongzheng on 2017/6/23.
 * Created with IntelliJ IDEA.
 */
@Service
public class TestService {

    private static final Logger LOGGER = LoggerFactory.getLogger(TestService.class);

    @Resource
    private HelloClient helloClient;

    @HystrixCommand(fallbackMethod = "fallback")
    public String test() {
        String content;
        try {
            content = helloClient.sayHello("孔令圳");
        } catch (Exception e) {
            throw new RuntimeException("远程服务调研失败", e);
        }
        return content;
    }

    public String fallback() {
        LOGGER.info("异常发生，进入fallback方法");
        return "调用出错，服务降级";
    }
}
